package com.neoenox.neotwix;

import task.AuthInitTask;
import task.AuthUrlTask;
import twitter4j.Twitter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import auth.Auth;

import com.neoenox.twitterapp.R;

public class AuthActivity extends Activity
{
	private Auth auth;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_auth);
		auth = new Auth();
		new AuthUrlTask(this,auth).execute();
	}

	@Override
	protected void onNewIntent(Intent intent)
	{
		Log.v("auth","onNewIntent start");
		if (intent == null || intent.getData() == null || intent.getData().toString().indexOf("myapp://oauth") != -1)
		{
			Log.v(this.getClass().getSimpleName(), intent.getData().toString());
			String verifier = intent.getData().getQueryParameter("oauth_verifier");
			Log.v(this.getClass().getSimpleName(), verifier);

			Twitter twitter = null;
			new AuthInitTask(twitter, auth,this).execute(verifier);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.auth, menu);
		return true;
	}

}
